<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户姓名" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入用户姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['quick:employeeRoster:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['quick:employeeRoster:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['quick:employeeRoster:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['quick:employeeRoster:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          v-hasPermi="['quick:employeeRoster:edit']"
        >导入</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="employeeRosterList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="主键ID" align="center" prop="id" /> -->
      <!-- <el-table-column label="用户ID" align="center" prop="userId" /> -->
      <el-table-column label="用户姓名" align="center" prop="userName" />
      <el-table-column label="到岗日期" align="center" prop="onboardDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.onboardDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="在职岗位" align="center" prop="position" />
      <el-table-column label="身份证号" align="center" prop="idCardNumber" />
      <el-table-column label="手机号" align="center" prop="phoneNumber" />
      <el-table-column label="银行卡号" align="center" prop="bankCardNumber" />
      <el-table-column label="开户行名称" align="center" prop="bankName" />
      <el-table-column label="银行卡照片" align="center" prop="bankCardPhotoUrls">
        <template slot-scope="scope">
          <img v-if="scope.row.bankCardPhotoUrls" :src="scope.row.bankCardPhotoUrls" style="max-width: 80px; max-height: 80px;" />
          <span v-else>无</span>
        </template>
      </el-table-column>
      <el-table-column label="转正日期" align="center" prop="regularizationDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.regularizationDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="合同开始日期" align="center" prop="contractStartDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.contractStartDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="合同结束日期" align="center" prop="contractEndDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.contractEndDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="现住址" align="center" prop="currentAddress" />
      <el-table-column label="年龄" align="center" prop="age" />
      <el-table-column label="性别" align="center" prop="gender" />
      <el-table-column label="最高学历" align="center" prop="highestEducation" />
      <el-table-column label="紧急联系人" align="center" prop="emergencyContactInfo" />
      <el-table-column label="试用期薪资" align="center" prop="probationarySalary" />
      <el-table-column label="试用期时间描述" align="center" prop="probationaryPeriodDesc" />
      <el-table-column label="转正后工资" align="center" prop="regularizationSalary" />
      <el-table-column label="身份证正面照片" align="center" prop="idFrontPhotoUrls">
        <template slot-scope="scope">
          <img v-if="scope.row.idFrontPhotoUrls" :src="scope.row.idFrontPhotoUrls" style="max-width: 80px; max-height: 80px;" />
          <span v-else>无</span>
        </template>
      </el-table-column>
      <el-table-column label="身份证背面照片" align="center" prop="idBackPhotoUrls">
        <template slot-scope="scope">
          <img v-if="scope.row.idBackPhotoUrls" :src="scope.row.idBackPhotoUrls" style="max-width: 80px; max-height: 80px;" />
          <span v-else>无</span>
        </template>
      </el-table-column>
      <el-table-column label="离职日期" align="center" prop="dimissionDate" />
      <el-table-column label="入职时间" align="center" prop="entryTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.entryTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否签订劳动合同" align="center" prop="isContractSigned" />
      <el-table-column label="在职状态" align="center" prop="employmentStatus" />
      <el-table-column label="是否过试用期" align="center" prop="isProbationPassed" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['quick:employeeRoster:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['quick:employeeRoster:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改财务-约瑟员工花名册对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="用户姓名" prop="userId">
          <el-select v-model="form.userId" placeholder="请选择用户" filterable clearable @change="handleUserSelect">
            <el-option v-for="user in filteredUserList" :key="user.userId" :label="user.userName || user.nickName || user.name || user.userId" :value="user.userId" />
          </el-select>
        </el-form-item>
        <el-form-item label="到岗日期" prop="onboardDate">
          <el-date-picker clearable
            v-model="form.onboardDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择到岗日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="在职岗位" prop="position">
          <el-input v-model="form.position" placeholder="请输入在职岗位" />
        </el-form-item>
        <el-form-item label="身份证号" prop="idCardNumber">
          <el-input v-model="form.idCardNumber" placeholder="请输入身份证号" />
        </el-form-item>
        <el-form-item label="手机号" prop="phoneNumber">
          <el-input v-model="form.phoneNumber" placeholder="请输入手机号" />
        </el-form-item>
        <el-form-item label="银行卡号" prop="bankCardNumber">
          <el-input v-model="form.bankCardNumber" placeholder="请输入银行卡号" />
        </el-form-item>
        <el-form-item label="开户行名称" prop="bankName">
          <el-input v-model="form.bankName" placeholder="请输入开户行名称" />
        </el-form-item>
        <el-form-item label="银行卡照片" prop="bankCardPhotoUrls">
          <el-upload
            class="avatar-uploader"
            :action="fileUploadUrl"
            :headers="upload.headers"
            :show-file-list="false"
            :on-success="handleBankCardPhotoSuccess"
            :on-remove="handleBankCardPhotoRemove"
            :file-list="bankCardPhotoList"
            :limit="1"
            accept=".jpg, .jpeg, .png"
          >
            <img v-if="form.bankCardPhotoUrls" :src="form.bankCardPhotoUrls" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </el-form-item>
        <el-form-item label="转正日期" prop="regularizationDate">
          <el-date-picker clearable
            v-model="form.regularizationDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择转正日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="合同开始日期" prop="contractStartDate">
          <el-date-picker clearable
            v-model="form.contractStartDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择合同开始日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="合同结束日期" prop="contractEndDate">
          <el-date-picker clearable
            v-model="form.contractEndDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择合同结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="现住址" prop="currentAddress">
          <el-input v-model="form.currentAddress" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="年龄" prop="age">
          <el-input v-model="form.age" placeholder="请输入年龄" />
        </el-form-item>
        <el-form-item label="性别" prop="gender">
          <el-input v-model="form.gender" placeholder="请输入性别" />
        </el-form-item>
        <el-form-item label="最高学历" prop="highestEducation">
          <el-input v-model="form.highestEducation" placeholder="请输入最高学历" />
        </el-form-item>
        <el-form-item label="紧急联系人" prop="emergencyContactInfo">
          <el-input v-model="form.emergencyContactInfo" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="试用期薪资" prop="probationarySalary">
          <el-input v-model="form.probationarySalary" placeholder="请输入试用期薪资" />
        </el-form-item>
        <el-form-item label="试用期时间描述" prop="probationaryPeriodDesc">
          <el-input v-model="form.probationaryPeriodDesc" placeholder="请输入试用期时间描述" />
        </el-form-item>
        <el-form-item label="转正后工资" prop="regularizationSalary">
          <el-input v-model="form.regularizationSalary" placeholder="请输入转正后工资" />
        </el-form-item>
        <el-form-item label="身份证正面照片" prop="idFrontPhotoUrls">
          <el-upload
            class="avatar-uploader"
            :action="fileUploadUrl"
            :headers="upload.headers"
            :show-file-list="false"
            :on-success="handleIdFrontPhotoSuccess"
            :on-remove="handleIdFrontPhotoRemove"
            :file-list="idFrontPhotoList"
            :limit="1"
            accept=".jpg, .jpeg, .png"
          >
            <img v-if="form.idFrontPhotoUrls" :src="form.idFrontPhotoUrls" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </el-form-item>
        <el-form-item label="身份证背面照片" prop="idBackPhotoUrls">
          <el-upload
            class="avatar-uploader"
            :action="fileUploadUrl"
            :headers="upload.headers"
            :show-file-list="false"
            :on-success="handleIdBackPhotoSuccess"
            :on-remove="handleIdBackPhotoRemove"
            :file-list="idBackPhotoList"
            :limit="1"
            accept=".jpg, .jpeg, .png"
          >
            <img v-if="form.idBackPhotoUrls" :src="form.idBackPhotoUrls" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </el-form-item>
        <el-form-item label="离职日期" prop="dimissionDate">
          <el-date-picker clearable
            v-model="form.dimissionDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择离职日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="入职时间" prop="entryTime">
          <el-date-picker clearable
            v-model="form.entryTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择入职时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="是否签订劳动合同" prop="isContractSigned">
          <el-select v-model="form.isContractSigned" placeholder="请选择是否签订劳动合同">
            <el-option label="是" value="是"></el-option>
            <el-option label="否" value="否"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="在职状态" prop="employmentStatus">
          <el-select v-model="form.employmentStatus" placeholder="请选择在职状态">
            <el-option label="在职" value="在职"></el-option>
            <el-option label="离职" value="离职"></el-option>
            <el-option label="待入职审批" value="待入职审批"></el-option>
            <el-option label="待离职审批" value="待离职审批"></el-option>
            <el-option label="其他待审批变更" value="其他待审批变更"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否过试用期" prop="isProbationPassed">
          <el-select v-model="form.isProbationPassed" placeholder="请选择是否过试用期">
            <el-option label="未过" value="未过"></el-option>
            <el-option label="已过" value="已过"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 用户导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listEmployeeRoster, getEmployeeRoster, delEmployeeRoster, addEmployeeRoster, updateEmployeeRoster, uploadFile } from "@/api/quick/employeeRoster"
import request from "@/utils/request"
import { getToken } from "@/utils/auth"
import { checkRole } from "@/utils/permission"

export default {
  name: "EmployeeRoster",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 财务-约瑟员工花名册表格数据
      employeeRosterList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        userName: null,
        onboardDate: null,
        position: null,
        idCardNumber: null,
        phoneNumber: null,
        bankCardNumber: null,
        bankName: null,
        bankCardPhotoUrls: null,
        regularizationDate: null,
        contractStartDate: null,
        contractEndDate: null,
        currentAddress: null,
        age: null,
        gender: null,
        highestEducation: null,
        emergencyContactInfo: null,
        probationarySalary: null,
        probationaryPeriodDesc: null,
        regularizationSalary: null,
        idFrontPhotoUrls: null,
        idBackPhotoUrls: null,
        dimissionDate: null,
        employmentStatus: null,
        isProbationPassed: null,
        entryTime: null,
        isContractSigned: null,
      },
      // 表单参数
      form: {
        id: null,
        userId: null,
        userName: null,
        onboardDate: null,
        position: null,
        idCardNumber: null,
        phoneNumber: null,
        bankCardNumber: null,
        bankName: null,
        bankCardPhotoUrls: null,
        regularizationDate: null,
        contractStartDate: null,
        contractEndDate: null,
        currentAddress: null,
        age: null,
        gender: null,
        highestEducation: null,
        emergencyContactInfo: null,
        probationarySalary: null,
        probationaryPeriodDesc: null,
        regularizationSalary: null,
        idFrontPhotoUrls: null,
        idBackPhotoUrls: null,
        dimissionDate: null,
        employmentStatus: null,
        isProbationPassed: null,
        entryTime: null,
        isContractSigned: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      },
      // 表单校验
      rules: {
        userId: [
          { required: true, message: "请选择用户", trigger: "change" }
        ],
        userName: [
          { required: true, message: "用户姓名不能为空", trigger: "blur" }
        ],
      },
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 1,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/quick/employeeRoster/importData"
      },
      // 用户列表
      userList: [],
      // 当前用户ID
      currentUserId: null,
      // 银行卡照片文件列表
      bankCardPhotoList: [],
      // 身份证正面照片文件列表
      idFrontPhotoList: [],
      // 身份证背面照片文件列表
      idBackPhotoList: [],
      // 文件上传地址
      fileUploadUrl: process.env.VUE_APP_BASE_API + '/quick/employeeRoster/uploadImage',
    }
  },
  computed: {
    // 根据角色权限过滤用户列表
    filteredUserList() {
      // 如果是人事或admin角色，显示全部用户
      if (checkRole(['人事', 'admin'])) {
        return this.userList;
      }
      // 否则只显示当前用户
      return this.userList.filter(user => user.userId === this.currentUserId);
    }
  },
  created() {
    this.getCurrentUserInfo();
    this.getList();
    this.getUserList();
  },
  methods: {
    /** 获取当前用户信息 */
    getCurrentUserInfo() {
      // 从store中获取当前用户信息
      const userInfo = this.$store.state.user;
      this.currentUserId = userInfo.id;
    },
    
    /** 获取用户列表 */
    getUserList() {
      // 先测试单个角色请求
      console.log('开始获取用户列表...');
      
      request({
        url: '/system/user/listByRoleName',
        method: 'get',
        params: { roleName: '财务' }
      }).then(response => {
        console.log('单个角色测试响应:', response);
        console.log('响应数据结构:', JSON.stringify(response, null, 2));
        
        // 检查用户数据结构
        const testUsers = Array.isArray(response.data) ? response.data : (response.data?.data || response.rows || []);
        if (testUsers.length > 0) {
          console.log('测试用户数据示例:', testUsers[0]);
          console.log('测试用户字段:', Object.keys(testUsers[0]));
        }
        
        // 如果单个测试成功，再进行批量请求
        if (response && (response.data || response.rows)) {
          this.getAllRoleUsers();
        } else {
          console.error('单个角色测试失败，响应格式不正确');
          this.userList = [];
        }
      }).catch(error => {
        console.error('单个角色测试请求失败:', error);
        this.userList = [];
      });
    },
    
    /** 获取所有角色用户 */
    getAllRoleUsers() {
      // 需要查询的角色列表
      const roleNames = ['售前', '售后', '售中', '财务', '写手', '公司技术', '售前主管', '售中主管', '售后主管'];
      
      // 并发请求所有角色的用户
      const promises = roleNames.map(roleName => 
        request({
          url: '/system/user/listByRoleName',
          method: 'get',
          params: { roleName: roleName }
        })
      );
      
      Promise.all(promises).then(responses => {
        console.log('所有角色API响应:', responses);
        // 合并所有角色的用户，去重
        const allUsers = [];
        const userIdSet = new Set();
        
        responses.forEach((response, index) => {
          console.log(`角色 ${roleNames[index]} 的用户:`, response);
          // 根据后端AjaxResult结构，数据在response.data中
          const users = Array.isArray(response.data) ? response.data : (response.data?.data || response.rows || []);
          console.log(`角色 ${roleNames[index]} 的用户数据:`, users);
          users.forEach(user => {
            console.log('单个用户数据:', user);
            console.log('用户字段:', Object.keys(user));
            if (!userIdSet.has(user.userId)) {
              userIdSet.add(user.userId);
              allUsers.push(user);
            }
          });
        });
        
        console.log('合并后的用户列表:', allUsers);
        this.userList = allUsers;
      }).catch(error => {
        console.error('获取所有角色用户失败:', error);
        this.userList = [];
      });
    },
    
    /** 用户选择处理 */
    handleUserSelect(userId) {
      if (userId) {
        const selectedUser = this.userList.find(user => user.userId === userId);
        if (selectedUser) {
          // 兼容不同的用户名字段
          this.form.userName = selectedUser.userName || selectedUser.nickName || selectedUser.name || selectedUser.userId;
          console.log('选中用户:', selectedUser);
          console.log('设置用户名为:', this.form.userName);
        }
      }
    },
    
    /** 查询财务-约瑟员工花名册列表 */
    getList() {
      this.loading = true
      listEmployeeRoster(this.queryParams).then(response => {
        this.employeeRosterList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        userName: null,
        onboardDate: null,
        position: null,
        idCardNumber: null,
        phoneNumber: null,
        bankCardNumber: null,
        bankName: null,
        bankCardPhotoUrls: null,
        regularizationDate: null,
        contractStartDate: null,
        contractEndDate: null,
        currentAddress: null,
        age: null,
        gender: null,
        highestEducation: null,
        emergencyContactInfo: null,
        probationarySalary: null,
        probationaryPeriodDesc: null,
        regularizationSalary: null,
        idFrontPhotoUrls: null,
        idBackPhotoUrls: null,
        dimissionDate: null,
        employmentStatus: null,
        isProbationPassed: null,
        entryTime: null,
        isContractSigned: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      }
      this.resetForm("form")
      this.bankCardPhotoList = []
      this.idFrontPhotoList = []
      this.idBackPhotoList = []
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.queryParams.userId = null; // 清空用户ID
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      // 如果不是人事或admin角色，默认填写当前用户ID
      if (!checkRole(['人事', 'admin'])) {
        this.form.userId = this.currentUserId;
        this.handleUserSelect(this.currentUserId);
      }
      this.open = true;
      this.title = "添加财务-约瑟员工花名册";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getEmployeeRoster(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改财务-约瑟员工花名册"
        // 设置用户选择
        if (this.form.userId) {
          this.handleUserSelect(this.form.userId);
        }
        if (this.form.bankCardPhotoUrls) {
          this.bankCardPhotoList = [{ name: '银行卡照片', url: this.form.bankCardPhotoUrls }];
        }
        if (this.form.idFrontPhotoUrls) {
          this.idFrontPhotoList = [{ name: '身份证正面照片', url: this.form.idFrontPhotoUrls }];
        }
        if (this.form.idBackPhotoUrls) {
          this.idBackPhotoList = [{ name: '身份证背面照片', url: this.form.idBackPhotoUrls }];
        }
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateEmployeeRoster(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addEmployeeRoster(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除财务-约瑟员工花名册编号为"' + ids + '"的数据项？').then(function() {
        return delEmployeeRoster(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('quick/employeeRoster/export', {
        ...this.queryParams
      }, `employeeRoster_${new Date().getTime()}.xlsx`)
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "员工花名册导入"
      this.upload.open = true
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('quick/employeeRoster/importTemplate', {
      }, `employeeRoster_template_${new Date().getTime()}.xlsx`)
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false
      this.upload.isUploading = false
      this.$refs.upload.clearFiles()
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true })
      this.getList()
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit()
    },
    // 银行卡照片上传成功回调
    handleBankCardPhotoSuccess(response, file, fileList) {
      this.form.bankCardPhotoUrls = response.data.url;
    },
    // 银行卡照片移除回调
    handleBankCardPhotoRemove(file, fileList) {
      this.form.bankCardPhotoUrls = '';
    },
    // 身份证正面照片上传成功回调
    handleIdFrontPhotoSuccess(response, file, fileList) {
      this.form.idFrontPhotoUrls = response.data.url;
    },
    // 身份证正面照片移除回调
    handleIdFrontPhotoRemove(file, fileList) {
      this.form.idFrontPhotoUrls = '';
    },
    // 身份证背面照片上传成功回调
    handleIdBackPhotoSuccess(response, file, fileList) {
      this.form.idBackPhotoUrls = response.data.url;
    },
    // 身份证背面照片移除回调
    handleIdBackPhotoRemove(file, fileList) {
      this.form.idBackPhotoUrls = '';
    }
  }
}
</script>

<style>
.upload-demo .el-upload__tip {
  line-height: 1.2;
}

.el-upload__tip span {
  margin-right: 10px;
}

.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>
